package day6;

import day4.HomeWork.A;

import java.util.*;

//测试集合遍历
public class TestIterate {
    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        Set<String> set = new HashSet<>();
        Map<String, String> map = new HashMap();
        list.add("c++");
        list.add("java");
        list.add("mysql");
        list.add("html");
        System.out.println("标准for遍历:");
        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i));
        }
        System.out.println("增强for(底层是迭代器)遍历:");
        for (String s : list) {
            System.out.println(s);
            //list.remove(s);      //出现并发修改异常
        }

        System.out.println(list);
        System.out.println("迭代器遍历:");
        Iterator<String> it = list.iterator();
        while (it.hasNext()) {
            String s = it.next();
            System.out.println(s);
            //list.remove(it.next());   //出现并发修改异常
            if ("java".equals(s)) it.remove();
        }
        System.out.println(list);
    }
}
